<template>
	<!-- 系统设置模块-删除个险数据-->
	<div class="fillcontain">
		<!-- 标题 -->
		<div class="fastQuery">
			<el-row>
				<el-col :span="5" class="common-box">
					<el-col :span="6" class="common-lab">
						<label class="labelName">受理号</label>
					</el-col>
					<el-col :span="14">
						<el-input clearable v-model="searchParams.applnum" placeholder=""></el-input>
					</el-col>
				</el-col>
				<el-col :span="5" class="common-box">
					<el-col :span="6" class="common-lab">
						<label class="labelName">保单号</label>
					</el-col>
					<el-col :span="14">
						<el-input clearable v-model="searchParams.chdrnum" placeholder=""></el-input>
					</el-col>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-col :span="7" class="common-lab">
						<label class="labelName">受理日期</label>
					</el-col>
					<el-col :span="14">
						<el-date-picker v-model="searchParams.hprrcvdt" format="yyyyMMdd" value-format="yyyyMMdd" type="date">
						</el-date-picker>
						<!--<el-input clearable v-model="hprrcvdt" placeholder=""></el-input>-->
					</el-col>
				</el-col>
				<el-col :span="4" class="text_center">
					<el-button type="primary" icon="el-icon-search" @click="search"></el-button>
					<el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
				</el-col>
				<el-col :span="4" class="text_center">
					<el-button type="primary" plain  @click="seeLog">查看日志</el-button>
				</el-col>
			</el-row>
		</div>
		<div class="contain">
			<!-- 操作按钮 -->
			<div class="table_container">
				<el-table :data="tableData" highlight-current-row header-cell-class-name="table-header-class" style="width:100%">
					<el-table-column property="applnum" label="受理号" align='center'></el-table-column>
					<el-table-column property="chdrnum" label="保单号" align='center'></el-table-column>
					<el-table-column  label="任务状态" property="procflgName" align='center'></el-table-column>
					<el-table-column fixed="right" label="操作" align='center'>
						<template slot-scope="scope">
						    <span class="operationIcon" @click="removeData(scope.row)">
						        <!-- 删除操作 -->
						        <el-tooltip class="item" effect="light" content="删除" placement="">
						            <i class="el-icon-delete"></i>
						        </el-tooltip>
						    </span>
						</template>
					</el-table-column>
					<el-table-column property="procflg" v-if="false"></el-table-column>
				</el-table>
				<el-row>
					<el-col :span="24">
						<div class="pagination">
							<el-pagination background v-if='paginations.total > 0' :page-sizes="paginations.pageSizes" :page-size="paginations.pageSize"
							 :layout="paginations.layout" :total="paginations.total" :current-page='paginations.pageIndex' @current-change='handleCurrentChange'
							 @size-change='handleSizeChange'>
							</el-pagination>
						</div>
					</el-col>
				</el-row>
			</div>
		</div>
		
		<div>
			<!-- 日志查看弹框 -->
			<el-dialog title="操作记录" :visible.sync="drawer"  :width="'60%'" :before-close="handleClose"
			           center>
			  <div class="contain">
			    <div class="table_container">
			      <el-table
			          ref="multipleTable"
			          v-loading="loading"
			          :data="logList"
			          highlight-current-row
			          header-cell-class-name="table-header-class"
			          style="width:100%">
			        <el-table-column min-width="120" property="busiCode" label="受理号" align='center' show-overflow-tooltip>
			        </el-table-column>
			        <el-table-column min-width="120" property="busiMode" label="保单号" align='center' show-overflow-tooltip>
			        </el-table-column>
			        <el-table-column min-width="150" property="createId" label="操作人" align='center' show-overflow-tooltip>
			        </el-table-column>
			        <el-table-column min-width="120" property="createTime" label="删除时间" align='center' show-overflow-tooltip>
			        </el-table-column>
			      </el-table>
			      <!-- 分页信息 -->
			      <el-row>
			        <!-- <el-col :span="4" class="button_pagination">
			          <el-button type="primary" @click="bathchShow_newObject()">查看</el-button>
			        </el-col> -->
			        <el-col :span="24">
			          <div class="pagination">
			            <el-pagination background v-if='paginations1.total > 0' :page-sizes="paginations1.pageSizes"
			                           :page-size="paginations1.pageSize"
			                           :layout="paginations1.layout" :total="paginations1.total"
			                           :current-page='paginations1.pageIndex' @current-change='handleCurrentChange1'
			                           @size-change='handleSizeChange1'>
			            </el-pagination>
			          </div>
			        </el-col>
			      </el-row>
			    </div>
			  </div>
			  <!-- </div> -->
			</el-dialog>
		</div>
		
	</div>
</template>
<script>
	import TaskConstants ,{call} from "@/api/taskManager/common"
	import constant from "@/utils/constant";
	import { getToken } from '@/utils/auth' // 验权(从cookie中获取)
	import {
		Message,
		MessageBox
	} from 'element-ui';
	export default {
		data() {
			return {
				emptySearchParams: {}, //空的查询
				searchParams:{
					applnum:'',
					chdrnum:'',
					hprrcvdt:'',
					pageNumber:'',
					pageSize:''
				},
				drawer:false,
				loading:false,
				procflgList:[
					{
						name:"受理",
						value:"0"
					},
					{
						name:"建档",
						value:"1"
					},
					{
						name:"核保",
						value:"2"
					},
					{
						name:"照会",
						value:"3"
					},
					{
						name:"核决",
						value:"4"
					},
					{
						name:"未入账",
						value:"5"
					},
					{
						name:"结案",
						value:"6"
					},
				],
				userInfo:{},
				tableData:[],
				logList:[],
				//需要给分页组件传的信息
				paginations: {
					total: 0, // 总数
					pageIndex: 1, // 当前位于哪页
					pageSize: 10, // 1页显示多少条
					pageSizes: [5, 10, 15, 20], //每页显示多少条
					layout: "total, sizes, prev, pager, next, jumper", // 翻页属性
				},
				//日志分页组件传的信息
				paginations1: {
					total: 0, // 总数
					pageIndex: 1, // 当前位于哪页
					pageSize: 10, // 1页显示多少条
					pageSizes: [5, 10, 15, 20], //每页显示多少条
					layout: "total, sizes, prev, pager, next, jumper", // 翻页属性
				},
			}
		},
		created() {
			this.emptySearchParams = JSON.parse(JSON.stringify(this.searchParams));
			this.userInfo=JSON.parse(localStorage.getItem(getToken('token'))).userKeyInfo;
		},
		mounted() {},
		methods: {
			handleClose(done) {
			  this.drawer = false
			  this.loading = false
			},
			seeLog() {
				this.loading =true
				this.drawer = true
				this.logList=[]
				let param ={
					pageNumber:this.paginations1.pageIndex,
					pageSize:this.paginations1.pageSize,
					platform:"task-app"
				}
				call(TaskConstants.apis.deleteDataLog,param,"post").then(result =>{
					if (result.resultCode == constant.SUCCESS && result.data!=null) {
						this.logList = result.data.rows
						this.paginations1.total = result.data.total
						this.paginations1.pageIndex = result.data.pageNum
					}
					this.loading =false
				})
			},
			resetSearch() {
				this.applnum = '';
				this.hprrcvdt = '';
				this.companybranch = '';
			},
			changeName(flag){
				for (let item of this.procflgList) {
					if (item.value == flag){
						return item.name;
					}
				}
				return flag
			},
			search() {
				if (!this.searchParams.applnum && !this.searchParams.hprrcvdt && !this.searchParams.chdrnum) {
					this.$message.error('请输入查询条件！');
					return false;
				}
				this.tableData=[]
				this.$store.dispatch('loading/CHNAGE_SUBLOADING', true);
				this.searchParams.pageNumber=this.paginations.pageIndex;
				this.searchParams.pageSize=this.paginations.pageSize;
				call(TaskConstants.apis.deleteDataQueryList,this.searchParams,"post").then(res => {
					if (res.resultCode == constant.SUCCESS && res.data && res.data.list.length) {
						let pageData = res.data;
						this.paginations.total = pageData.total;
						this.paginations.currentPage = pageData.pageNum;
						this.tableData = pageData.list;
						this.tableData.forEach(item =>{
							item['procflgName'] = this.changeName(item.procflg)
						})
					}
					this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
				}).catch(err => {
					console.log(err);
					this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
				})
			},
			removeData(row) {
				let numReg = /[0-9]{1}/
				if(!numReg.test(row.procflg) || row.procflg < 4) {
					this.$message({
					  message: '状态不符，无法执行删除操作！',
					  type: 'error'
					});
					return ;
				}
				let param = {
					applnum:row.applnum,
					chdrnum:row.chdrnum,
					procflg:row.procflg,
					userId:this.userInfo.account
				}
				MessageBox.confirm("清除受理号"+row.applnum+"个险中台数据", '警告', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				  type: 'warning'
				}).then(() => {
				   this.$store.dispatch('loading/CHNAGE_SUBLOADING', true);
				   call(TaskConstants.apis.deleteDataDel,param,"post").then(res =>{
					  if (res.resultCode == constant.SUCCESS ) {
						this.$message({
						  message: '删除成功！',
						  type: 'success'
						});
						this.search()
					  }
					this.$store.dispatch('loading/CHNAGE_SUBLOADING', false); 
				   })
				});
			},
			resetSearch() {
				this.searchParams = JSON.parse(JSON.stringify(this.emptySearchParams));
			},
			// 每页多少条切换
			handleSizeChange(pageSize) {
				this.paginations.pageIndex = 1;
				this.paginations.pageSize = pageSize;
				this.search();
			},
			// 上下分页
			handleCurrentChange(page) {
				this.paginations.pageIndex = page;
				this.search();
			},
			// 每页多少条切换
			handleSizeChange1(pageSize) {
				this.paginations1.pageIndex = 1;
				this.paginations1.pageSize = pageSize;
				this.seeLog()
			},
			// 上下分页
			handleCurrentChange1(page) {
				this.paginations1.pageIndex = page;
				this.seeLog();
			},
		},
		computed: {},
	}
</script>
<style lang="less" scoped>
	.fillcontain {
		padding-bottom: 0;

		.fastQuery {
			padding: 15px 20px 10px 20px;
			background: #fff;

			.fastQuery_title {
				color: #666;
				padding: 6px 0px;
			}
		}
	}

	.contain {
		background: #fff;
		padding: 10px;
		margin-bottom: 20px;
	}

	.pagination {
		padding: 10px 20px;
		text-align: right;
	}
</style>
